# 今天作业： 自己去了解一下git的分支管理 然后创建两个分支dev1 和dev2
# 两个分支同时修改同一个文件，再合并到master  看一下冲突
import random
import time

class Role:
    def __init__(self,name,sex):
        self.name = name
        self.sex = sex
        self.blood = 200
        self.gold = 600
        self.damage = 30
        self.defence = 10
        self.euip = []
        self.room = None

    def shop(self):
        attack_equip = {"1":["暗影战斧",250,15],"2":["无尽战刃",350,20]}
        defense_equip = {"3":["反伤刺甲",200,10],"4":["魔女斗篷",300,15]}
        for i in attack_equip:
            print(f"{attack_equip[i][0]}:{attack_equip[i][1]}金币,攻击力提升{attack_equip[i][2]},编号{i}")
        for i in defense_equip:
            print(f"{defense_equip[i][0]}:{defense_equip[i][1]}金币,防御提升{defense_equip[i][2]},编号{i}")
        print(f"你还有{self.gold}金币")
        attack_lst = ["1","2"]
        defense_lst = ["3","4"]
        prompt = 0
        while True:
            num = input("购买一件装备请输入1,购买两件装备请输入2,不购买装备输入其他即可:")
            if num == "1":
                while self.gold >= 200:
                    print("退出输入exit")
                    num1 = input("请输入要购买装备的编号：")
                    if num1 in attack_lst:
                        if self.gold >= attack_equip[num1][1]:
                            self.euip.append(attack_equip[num1][0])
                            self.gold -= attack_equip[num1][1]
                            self.damage += attack_equip[num1][2]
                            prompt = 1
                            print("购买装备成功")
                            break
                        else:
                            print("你的金币不足，购买失败")
                    elif num1 in defense_lst:
                        if self.gold >= defense_equip[num1][1]:
                            self.euip.append(defense_equip[num1][0])
                            self.gold -= defense_equip[num1][1]
                            self.defence += defense_equip[num1][2]
                            prompt = 1
                            print("购买装备成功")
                            break
                        else:
                            print("你的金币不足，购买失败")
                    elif num1 == "exit":
                        prompt = 1
                        break
                    else:
                        print("输入的编号有误，请重新输入")
                else:
                    print("金币不足，购买不了一件装备")
            elif num == "2":
                while self.gold >= 450:
                    print("退出请输入exit")
                    num2 = input("请输入要购买的第一件装备的编号：")
                    num3 = input("请输入要购买的第二件装备的编号：")
                    if num2 in attack_lst and num3 in attack_lst:
                        if self.gold >= attack_equip[num2][1] + attack_equip[num3][1]:
                            self.euip.append(attack_equip[num2][0])
                            self.euip.append(attack_equip[num3][0])
                            self.gold -= attack_equip[num2][1]
                            self.gold -= attack_equip[num3][1]
                            self.damage += attack_equip[num2][2]
                            self.damage += attack_equip[num3][2]
                            prompt = 1
                            print("购买装备成功")
                            break
                        else:
                            print("你的金币不足，购买失败")
                    elif num2 in attack_lst and num3 in defense_lst:
                        if self.gold >= attack_equip[num2][1] + defense_equip[num3][1]:
                            self.euip.append(attack_equip[num2][0])
                            self.euip.append(defense_equip[num3][0])
                            self.gold -= attack_equip[num2][1]
                            self.gold -= defense_equip[num3][1]
                            self.damage += attack_equip[num2][2]
                            self.defence += defense_equip[num3][2]
                            prompt = 1
                            print("购买装备成功")
                            break
                        else:
                            print("你的金币不足，购买失败")
                    elif num2 in defense_lst and num3 in attack_lst:
                        if self.gold >= defense_equip[num2][1] + attack_equip[num3][1]:
                            self.euip.append(defense_equip[num2][0])
                            self.euip.append(attack_equip[num3][0])
                            self.gold -= defense_equip[num2][1]
                            self.gold -= attack_equip[num3][1]
                            self.defence += defense_equip[num2][2]
                            self.damage += attack_equip[num3][2]
                            prompt = 1
                            print("购买装备成功")
                            break
                        else:
                            print("你的金币不足，购买失败")
                    elif num2 in defense_lst and num3 in defense_lst:
                        if self.gold >= defense_equip[num2][1] + defense_equip[num3][1]:
                            self.euip.append(defense_equip[num2][0])
                            self.euip.append(defense_equip[num3][0])
                            self.gold -= defense_equip[num2][1]
                            self.gold -= defense_equip[num3][1]
                            self.defence += defense_equip[num2][2]
                            self.defence += defense_equip[num3][2]
                            prompt = 1
                            print("购买装备成功")
                            break
                        else:
                            print("你的金币不足，购买失败")
                    elif num2 == "exit" or num3 == "exit":
                        prompt = 1
                        break
                    else:
                        print("输入的编号有误，请重新输入")
                else:
                    print("金币不足，购买不了两件装备")
            else:
                break
            if prompt:
                break

    def sell_equip(self):
        attack_equip = {"1": ["暗影战斧", 250, 15], "2": ["无尽战刃", 350, 20]}
        defense_equip = {"3": ["反伤刺甲", 200, 10], "4": ["魔女斗篷", 300, 15]}
        while True:
            print("退出请输入'exit'")
            num = input("请输入要出售的装备编号：")
            if num in attack_equip:
                if attack_equip[num][0] in self.euip:
                    self.euip.remove(attack_equip[num][0])
                    self.damage -= attack_equip[num][2]
                    self.gold += attack_equip[num][1]
                    break
                else:
                    print(f"{self.name}没有这件装备，请重新输入")
            elif num in defense_equip:
                if defense_equip[num][0] in self.euip:
                    self.euip.remove(defense_equip[num][0])
                    self.defence -= defense_equip[num][2]
                    self.gold += defense_equip[num][1]
                    break
                else:
                    print(f"{self.name}没有这件装备，请重新输入")
            elif num == "exit":
                break
            else:
                print("输入有误，请重新输入")

class Room:
    def __init__(self,name):
        self.name = name
        self.member = []

    def join_room(self,role):
        if role.room == None:
            if len(self.member) < 2:
                role.room = self.name
                self.member.append(role.name)
                print(f"{role.name}已进入{self.name}房间")
            else:
                print(f"{self.name}房间人数已满，进入失败")
        else:
            print(f"{role.name}已加入其他房间，进入失败")

    def quit_room(self,role):
        self.member.remove(role.name)
        role.room = None
        print(f"{role.name}已退出房间")

    def battle(self,role1,role2):
        if role1.room != None and role2.room != None:
            if role1.room == role2.room:
                begin = random.randint(1,2)
                while role1.blood > 0 and role2.blood > 0:
                    if begin == 1:
                        print(f"{role1.name}进行攻击")
                        role2.blood -= role1.damage - role2.defence
                        print(f"{role2.name}血量减少{role1.damage - role2.defence},还剩{role2.blood}血")
                        if role2.blood <= 0:
                            break
                        time.sleep(1)
                        print(f"{role2.name}进行攻击")
                        role1.blood -= role2.damage - role1.defence
                        print(f"{role1.name}血量减少{role2.damage - role1.defence},还剩{role1.blood}血")
                        time.sleep(1)
                    else:
                        print(f"{role2.name}进行攻击")
                        role1.blood -= role2.damage - role1.defence
                        print(f"{role1.name}血量减少{role2.damage - role1.defence},还剩{role1.blood}血")
                        if role1.blood <= 0:
                            break
                        time.sleep(1)
                        print(f"{role1.name}进行攻击")
                        role2.blood -= role1.damage - role2.defence
                        print(f"{role2.name}血量减少{role1.damage - role2.defence},还剩{role2.blood}血")
                        time.sleep(1)
                if role1.blood <= 0:
                    print(f"{role2.name}胜利,奖励金币200")
                    print(f"{role1.name}失败,扣除金币100")
                    role2.gold += 200
                    role1.gold -= 100
                    role1.blood = 200
                    role2.blood = 200
                else:
                    print(f"{role1.name}胜利,奖励金币200")
                    print(f"{role2.name}失败,扣除金币100")
                    role1.gold += 200
                    role2.gold -= 100
                    role1.blood = 200
                    role2.blood = 200

            else:
                print(f"{role1.name}和{role2.name}不在同一个房间，不能进行战斗")
        else:
            print("玩家还未加入房间，不能进行战斗")

room1 = Room("排位")
room2 = Room("巅峰赛")
print("欢迎进入王者荣耀")

def create_role(i):
    name = input(f"请输入第{i}个角色的名字：")
    while True:
        sex = input(f"请输入第{i}个角色的性别（男or女）：")
        if sex != "男" and sex != "女":
            print("输入有误，请重新输入")
        else:
            return name,sex

for i in range(1,3):
    if i == 1:
        name1,sex1 = create_role(i)
        role1 = Role(name1,sex1)
        print(f"{role1.name}创建成功")
    else:
        name2, sex2 = create_role(i)
        role2 = Role(name2, sex2)
        print(f"{role2.name}创建成功")

while True:
    num = input("查看角色信息请按'1',购买装备请按'2',出售装备请按'3',加入房间请按'4',退出房间请按'5',进入战斗请按'6',退出输入其他：")
    if num == '1':
        print(f"姓名：{role1.name},血量：{role1.blood},金币：{role1.gold},基础伤害：{role1.damage},基础防御{role1.defence},装备：{role1.euip},进入的房间：{role1.room}")
        print(f"姓名：{role2.name},血量：{role2.blood},金币：{role2.gold},基础伤害：{role2.damage},基础防御{role2.defence},装备：{role2.euip},进入的房间：{role2.room}")
    elif num == '2':
        print(f"{role1.name}进行购买装备")
        role1.shop()
        print(f"{role2.name}进行购买装备")
        role2.shop()
    elif num == '3':
        print(f"{role1.name}进行出售装备")
        role1.sell_equip()
        print(f"{role2.name}进行出售装备")
        role2.sell_equip()
    elif num == '4':
        print(f"{role1.name}选择房间")
        while True:
            num2 = input(f"进入{room1.name}请输入'1',进入{room2.name}请输入'2',退出选择房间输入'3':")
            if num2 == '1':
                room1.join_room(role1)
                break
            elif num2 == '2':
                room2.join_room(role1)
                break
            elif num2 == '3':
                break
            else:
                print("你的输入有误，请重新输入")
        print(f"{role2.name}选择房间")
        while True:
            num2 = input(f"进入{room1.name}请输入'1',进入{room2.name}请输入'2',退出选择房间输入'3':")
            if num2 == '1':
                room1.join_room(role2)
                break
            elif num2 == '2':
                room2.join_room(role2)
                break
            elif num2 == '3':
                break
            else:
                print("你的输入有误，请重新输入")
    elif num == '5':
        num3 = input(f"{role1.name}需要退出房间,请输入'1',如不需要输入其他：")
        if num3 == '1':
            if role1.room != None:
                room_name = role1.room
                if room_name == room1.name:
                    room1.quit_room(role1)
                else:
                    room2.quit_room(role1)
            else:
                print(f"{role1.name}还未加入房间")
        num4 = input(f"{role2.name}需要退出房间,请输入'1',如不需要输入其他：")
        if num4 == '1':
            if role2.room != None:
                room_name = role2.room
                if room_name == room1.name:
                    room1.quit_room(role2)
                else:
                    room2.quit_room(role2)
            else:
                print(f"{role2.name}还未加入房间")
    elif num == '6':
        room_name = role1.room
        if room_name == room1.name:
            room1.battle(role1,role2)
            num5 = input("继续游戏请输入'1',退出输入其他：")
            if num5 != '1':
                print("游戏结束，已退出王者荣耀")
        else:
            room2.battle(role1,role2)
            num5 = input("继续游戏请输入'1',退出输入其他：")
            if num5 != '1':
                print("游戏结束，已退出王者荣耀")
    else:
        print("游戏结束，已退出王者荣耀")
        break

















































